package com.hdd.art.biz.show.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdd.art.biz.show.dto.ArtShowVo;
import com.hdd.art.biz.show.entity.ArtShow;
import com.hdd.art.biz.show.entity.ArtShowSetup;
import com.hdd.art.biz.show.mapper.ArtShowMapper;
import com.hdd.art.biz.show.service.ArtShowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdd.art.biz.show.service.ArtShowSetupService;
import com.hdd.art.biz.show.service.MemberArtService;
import com.hdd.art.utils.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 美术馆 服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-06-27
 */
@Service
public class ArtShowServiceImpl extends ServiceImpl<ArtShowMapper, ArtShow> implements ArtShowService {


    @Autowired
    private ArtShowSetupService artShowSetupService;
    @Autowired
    private MemberArtService memberArtService;
    @Override
    public ArtShow findArtShowById(String artId) {
        return baseMapper.selectById(artId);
    }

    @Override
    public ArtShow findArtShowByUserId(String userId) {
        QueryWrapper<ArtShow> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<ArtShow> getArtShowList() {
        QueryWrapper<ArtShow> wrapper = new QueryWrapper<>();
        return baseMapper.selectList(wrapper);
    }

    @Override
    public void updateShow(ArtShow artShow) {
        baseMapper.updateById(artShow);
    }

    @Override
    @Transactional
    public void addArtShow(ArtShow artShow) {
        baseMapper.insert(artShow);
        ArtShowSetup artShowSetup = new ArtShowSetup();
        artShowSetup.setArtId(artShow.getArtId());
        artShowSetupService.add(artShowSetup);
        memberArtService.insert(artShow.getUserId(),artShow.getArtId());

    }


    @Override
    public List<ArtShowVo> myArtRecord(String userId) {
        List<ArtShow> artShowList = baseMapper.myArtRecord(userId);
        List<ArtShowVo> artShowVos = new ArrayList<>();
        ArtShowVo vo;
        for(ArtShow art: artShowList){
            vo = new ArtShowVo();
            vo.setArtId(art.getArtId());
            vo.setName(art.getName());
            vo.setLogoUrl(art.getLogoUrl());
            vo.setWorks(100);
            vo.setFans(200);
            vo.setShows(300);
            artShowVos.add(vo);
        }

        return artShowVos;
    }


}
